#!/usr/bin/env python3
"""
添加测试竞赛数据到数据库
"""
import asyncio
from datetime import datetime, timedelta
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.database import async_engine
from app.models.competition import Competition, CompetitionType, CompetitionStatus, DifficultyLevel

async def create_sample_competitions():
    """创建示例竞赛数据"""
    
    async with AsyncSession(async_engine) as session:
        # 示例竞赛数据
        competitions = [
            {
                "title": "2024全球AI创新挑战赛",
                "description": "探索人工智能的无限可能，用AI技术解决现实世界的问题。比赛涵盖机器学习、深度学习、自然语言处理等多个领域。",
                "platform": "Kaggle",
                "category": "人工智能",
                "difficulty": DifficultyLevel.INTERMEDIATE,
                "type": CompetitionType.HACKATHON,
                "status": CompetitionStatus.ONGOING,
                "start_date": datetime.now() - timedelta(days=5),
                "end_date": datetime.now() + timedelta(days=25),
                "registration_end": datetime.now() + timedelta(days=15),
                "submission_deadline": datetime.now() + timedelta(days=25),
                "deadline": datetime.now() + timedelta(days=25),
                "prize_pool": 50000,
                "max_team_size": 4,
                "min_team_size": 1,
                "tags": ["AI", "机器学习", "深度学习", "Python"],
                "rules": "参赛者需要使用提供的数据集训练模型，并提交预测结果。评分标准为准确率和创新性。要求：Python编程经验、机器学习基础、团队协作能力。",
                "banner_image": "https://trae-api-us.mchost.guru/api/ide/v1/text_to_image?prompt=AI%20innovation%20challenge%20futuristic%20technology%20competition&image_size=landscape_16_9",
                "external_url": "https://www.kaggle.com/competitions/ai-challenge-2024",
                "is_featured": True,
                "is_public": True,
                "view_count": 1250,
                "participants_count": 89,
                "slug": "ai-innovation-challenge-2024"
            },
            {
                "title": "Web3去中心化应用开发大赛",
                "description": "构建下一代去中心化应用，探索区块链技术的创新应用。支持以太坊、Polygon等多个区块链平台。",
                "platform": "DevPost",
                "category": "区块链",
                "difficulty": DifficultyLevel.ADVANCED,
                "type": CompetitionType.HACKATHON,
                "status": CompetitionStatus.ONGOING,
                "start_date": datetime.now() - timedelta(days=10),
                "end_date": datetime.now() + timedelta(days=20),
                "registration_end": datetime.now() + timedelta(days=10),
                "submission_deadline": datetime.now() + timedelta(days=20),
                "deadline": datetime.now() + timedelta(days=20),
                "prize_pool": 30000,
                "max_team_size": 5,
                "min_team_size": 2,
                "tags": ["Web3", "区块链", "智能合约", "DeFi"],
                "rules": "开发一个完整的DApp，包括智能合约和前端界面。评分标准包括技术实现、用户体验和商业价值。要求：Solidity编程经验、Web3开发基础、前端开发技能。",
                "banner_image": "https://trae-api-us.mchost.guru/api/ide/v1/text_to_image?prompt=Web3%20blockchain%20decentralized%20application%20development&image_size=landscape_16_9",
                "external_url": "https://devpost.com/hackathons/web3-dapp-challenge",
                "is_featured": True,
                "is_public": True,
                "view_count": 890,
                "participants_count": 67,
                "slug": "web3-dapp-challenge-2024"
            },
            {
                "title": "移动应用创新设计赛",
                "description": "设计和开发创新的移动应用，解决用户日常生活中的痛点。支持iOS和Android平台。",
                "platform": "HackerEarth",
                "category": "移动开发",
                "difficulty": DifficultyLevel.BEGINNER,
                "type": CompetitionType.DESIGN_CONTEST,
                "status": CompetitionStatus.ONGOING,
                "start_date": datetime.now() - timedelta(days=3),
                "end_date": datetime.now() + timedelta(days=30),
                "registration_end": datetime.now() + timedelta(days=20),
                "submission_deadline": datetime.now() + timedelta(days=30),
                "deadline": datetime.now() + timedelta(days=30),
                "prize_pool": 15000,
                "max_team_size": 1,
                "min_team_size": 1,
                "tags": ["移动开发", "iOS", "Android", "UI/UX"],
                "rules": "开发一个原创移动应用，提交应用商店链接或APK文件。评分标准为创新性、用户体验和技术实现。要求：移动开发经验、UI/UX设计能力、创新思维。",
                "banner_image": "https://trae-api-us.mchost.guru/api/ide/v1/text_to_image?prompt=mobile%20app%20development%20innovation%20smartphone%20design&image_size=landscape_16_9",
                "external_url": "https://www.hackerearth.com/challenges/hackathon/mobile-app-innovation/",
                "is_featured": False,
                "is_public": True,
                "view_count": 567,
                "participants_count": 123,
                "slug": "mobile-app-innovation-2024"
            },
            {
                "title": "数据科学马拉松",
                "description": "使用大数据技术分析和预测商业趋势。比赛提供真实的商业数据集，挑战参赛者的数据分析能力。",
                "platform": "Kaggle",
                "category": "数据科学",
                "difficulty": DifficultyLevel.INTERMEDIATE,
                "type": CompetitionType.DATA_SCIENCE,
                "status": CompetitionStatus.ONGOING,
                "start_date": datetime.now() - timedelta(days=7),
                "end_date": datetime.now() + timedelta(days=18),
                "registration_end": datetime.now() + timedelta(days=8),
                "submission_deadline": datetime.now() + timedelta(days=18),
                "deadline": datetime.now() + timedelta(days=18),
                "prize_pool": 25000,
                "max_team_size": 3,
                "min_team_size": 1,
                "tags": ["数据科学", "机器学习", "统计分析", "Python", "R"],
                "rules": "分析提供的数据集，构建预测模型并提交结果。评分基于模型准确性和分析深度。要求：数据分析经验、统计学基础、Python或R编程。",
                "banner_image": "https://trae-api-us.mchost.guru/api/ide/v1/text_to_image?prompt=data%20science%20analytics%20machine%20learning%20visualization&image_size=landscape_16_9",
                "external_url": "https://www.kaggle.com/competitions/data-science-marathon",
                "is_featured": True,
                "is_public": True,
                "view_count": 2100,
                "participants_count": 156,
                "slug": "data-science-marathon-2024"
            },
            {
                "title": "游戏开发48小时挑战",
                "description": "在48小时内从零开始创建一个完整的游戏。主题将在比赛开始时公布，考验参赛者的快速开发能力。",
                "platform": "itch.io",
                "category": "游戏开发",
                "difficulty": DifficultyLevel.EXPERT,
                "type": CompetitionType.HACKATHON,
                "status": CompetitionStatus.PUBLISHED,
                "start_date": datetime.now() + timedelta(days=2),
                "end_date": datetime.now() + timedelta(days=4),
                "registration_end": datetime.now() + timedelta(days=1),
                "submission_deadline": datetime.now() + timedelta(days=4),
                "deadline": datetime.now() + timedelta(days=4),
                "prize_pool": 10000,
                "max_team_size": 4,
                "min_team_size": 1,
                "tags": ["游戏开发", "Unity", "Unreal", "独立游戏"],
                "rules": "在48小时内开发一个完整的游戏，包括玩法、美术和音效。评分标准为创新性、完成度和趣味性。要求：游戏开发经验、快速原型制作能力、创意思维。",
                "banner_image": "https://trae-api-us.mchost.guru/api/ide/v1/text_to_image?prompt=game%20development%2048%20hour%20challenge%20indie%20gaming&image_size=landscape_16_9",
                "external_url": "https://itch.io/jam/game-dev-48h-challenge",
                "is_featured": False,
                "is_public": True,
                "view_count": 789,
                "participants_count": 45,
                "slug": "game-dev-48h-challenge-2024"
            }
        ]
        
        # 添加竞赛到数据库
        for comp_data in competitions:
            competition = Competition(**comp_data)
            session.add(competition)
        
        await session.commit()
        print(f"成功添加 {len(competitions)} 个示例竞赛到数据库")

async def main():
    """主函数"""
    try:
        await create_sample_competitions()
        print("数据初始化完成！")
    except Exception as e:
        print(f"数据初始化失败: {e}")

if __name__ == "__main__":
    asyncio.run(main())